package com.fuss.uicustomviews

import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.Toast
import androidx.constraintlayout.widget.ConstraintLayout
import com.fuss.activitytest.R
import kotlinx.android.synthetic.main.title.view.*

/**
 * <pre>
 *     author : Mr.Fu
 *     e-mail : 18622268981@163.com
 *     time   : 2021/07/28
 *     desc   : 自定义控件   标题栏
 *     version: 1.0
 * </pre>
 */
class TitleLayout(context: Context?, attrs: AttributeSet?) : ConstraintLayout(context, attrs) {

    init {
        LayoutInflater.from(context).inflate(R.layout.title, this)

        back_btn.setOnClickListener {

            val activity = context as Activity
            activity.finish()
        }

        edit_btn.setOnClickListener {

            Toast.makeText(context, "You clicked Edit Button!", Toast.LENGTH_SHORT).show()
        }
    }

    fun setTitle(title: String) {

        title_text.text = title
    }
}